/**
 * <pre>
 * Copyright:		Copyright(C) 2011-2012, ketayao.com
 * Filename:		com.ketayao.ketacustom.util.dwz.AjaxObject.java
 * Class:			AjaxObject
 * Date:			2012-6-8
 * Author:			<a href="mailto:ketayao@gmail.com">ketayao</a>
 * Version          1.1.0
 * Description:		
 *
 * </pre>
 **/

package com.fly.core.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "接口返回对象")
public class AjaxObject
{
    // 状态码
    public static final int STATUS_CODE_SUCCESS = 0;
    
    public static final int STATUS_CODE_FAILURE = 9999;
    
    @ApiModelProperty(value = "状态码，成功0，失败9999", required = true)
    private int code = STATUS_CODE_SUCCESS;
    
    @ApiModelProperty(value = "提示信息")
    private String message = "";
    
    public AjaxObject()
    {
        
    }
    
    public AjaxObject(String message)
    {
        this.message = message;
    }
    
    /**
     * 构造函数
     * 
     * @param statusCode
     */
    public AjaxObject(int code)
    {
        super();
        this.code = code;
    }
    
    /**
     * 构造函数
     * 
     * @param statusCode
     * @param message
     */
    public AjaxObject(int code, String message)
    {
        super();
        this.code = code;
        this.message = message;
    }
    
    /**
     * 返回 statusCode 的值
     * 
     * @return statusCode
     */
    public int getCode()
    {
        return code;
    }
    
    /**
     * 设置 statusCode 的值
     * 
     * @param statusCode
     */
    public void setCode(int code)
    {
        this.code = code;
    }
    
    /**
     * 返回 message 的值
     * 
     * @return message
     */
    public String getMessage()
    {
        return message;
    }
    
    /**
     * 设置 message 的值
     * 
     * @param message
     */
    public AjaxObject setMessage(String message)
    {
        this.message = message;
        return this;
    }
    
    public static AjaxObject newOk(String message)
    {
        return new AjaxObject(STATUS_CODE_SUCCESS, message);
    }
    
    public static AjaxObject newError(String message)
    {
        return new AjaxObject(STATUS_CODE_FAILURE, message);
    }
    
    /**
     * @return
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append("{").append("\"code\":\"" + code + "\",").append("\"message\":\"" + message + "\",").append("}");
        return buffer.toString();
    }
    
}
